<?php

class Application_Model_PlayerProfile extends Zend_Db_Table_Abstract
{
	protected $_roundSettings = "round_settings";
	protected $_race = "race";
	protected $_class = "hero_class";
	protected $_userStats = "user_stats";
	protected $_lightUserArmy = "light_user_army";
	protected $_darkUserArmy = "dark_user_army";
	protected $_unitsPower = "units_power";
	protected $_unitsIncome =  "units_income";
		
	function getPlayerArmyDetails($user_id)
    {
    	
    	$select = $this->_db->select()
    						->from($this->_roundSettings)
    						->where('user_fk = ?', $user_id);
    	$result = $this->getAdapter()->fetchRow($select);
    	
    	if( $result['class_fk'] == 1 )
    	{
    		$select = $this->_db->select()
            	 ->from(array('us' => $this->_userStats))
             	->join(array('rs' => $this->_roundSettings), 'us.user_fk = rs.user_fk', array('alias'))
             	->join(array('c' => $this->_class), 'rs.class_fk = c.id', array('class_name'=>'name'))
             	->join(array('r' => $this->_race), 'rs.race_fk = r.id', array('race_name'=>'name'))
             	->join(array('army'=> $this->_lightUserArmy), 'army.user_fk = rs.user_fk')
             	->join(array('units_power'=> $this->_unitsPower), 'units_power.race_id = rs.race_fk', array('p1'=>'lvl1','p2'=>'lvl2','p3'=>'lvl3','p4'=>'lvl4','p5'=>'lvl5','p6'=>'lvl6'))
             	->join(array('units_income'=> $this->_unitsIncome), 'units_power.race_id = rs.race_fk', array('i1'=>'lvl1','i2'=>'lvl2','i3'=>'lvl3','i4'=>'lvl4','i5'=>'lvl5','i6'=>'lvl6'))
             	->where('us.user_fk=?',$user_id);
    	}
    	else
    	{
    		$select = $this->_db->select()
            	 ->from(array('us' => $this->_userStats))
             	->join(array('rs' => $this->_roundSettings), 'us.user_fk = rs.user_fk', array('alias'))
             	->join(array('c' => $this->_class), 'rs.class_fk = c.id', array('class_name'=>'name'))
             	->join(array('r' => $this->_race), 'rs.race_fk = r.id', array('race_name'=>'name'))
             	->join(array('army'=> $this->_darkUserArmy), 'army.user_fk = rs.user_fk')
             	->join(array('units_power'=> $this->_unitsPower), 'units_power.race_id = rs.race_fk', array('p1'=>'lvl1','p2'=>'lvl2','p3'=>'lvl3','p4'=>'lvl4','p5'=>'lvl5','p6'=>'lvl6'))
             	->join(array('units_income'=> $this->_unitsIncome), 'units_power.race_id = rs.race_fk', array('i1'=>'lvl1','i2'=>'lvl2','i3'=>'lvl3','i4'=>'lvl4','i5'=>'lvl5','i6'=>'lvl6'))
             	->where('us.user_fk=?',$user_id);
    	}
    	$result = $this->getAdapter()->fetchRow($select);
    	return $result;
    }
    
//    function getPlayerTotalArmyCount($user_id, $class_name)
//    {
//    	if( $class_name == 'Light' )
//    	{
//    		$select = $this->_db->select()
//            	 ->from($this->_lightUserArmy, array('lvl1'+'lvl2'+'lvl3'+'lvl4'+'lvl5'+'lvl6'))
//             	->where('user_fk=?',$user_id);
//    	}
//    	else
//    	{
//    			$select = $this->_db->select()
//            	 ->from($this->_darkUserArmy, array('lvl1'+'lvl2'+'lvl3'+'lvl4'+'lvl5'+'lvl6'))
//             	->where('user_fk=?',$user_id);
//    	}
//    	$result = $this->getAdapter()->fetchRow($select);
//    	return $result;
//    }
    
}

